package com.intercepter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.entity.User;


//检查用户有无登陆，防止没有登陆的用户访问后续页面
public class LoginIntercepter implements HandlerInterceptor {

	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		// TODO Auto-generated method stub
		String url=request.getRequestURI();
		
		if(url.indexOf("/login.action")>=0) {
			return true;
		
		}
		HttpSession session=request.getSession();
		User man=(User) session.getAttribute("Users");
		if(man!=null) {
			return true;
		}
		
		request.setAttribute("msg","你还没有登陆");
		request.getRequestDispatcher("/webface/login.jsp").forward(request, response);
		return false;
	}


	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub
		
	}

	
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		// TODO Auto-generated method stub
		
	}
     
	
	
	
	
	
	
}